home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / gfx / lise2.1 / lise / src / dat2l.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-31  |  1.4 KB  |  78 lines

  1. /* Convert data from a text file
  2.    max min zero_line
  3.    to a lise spectrum
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <spec.h>
  8.  
  9. float x,y,*spc,*err,*tim;
  10.  
  11. help()
  12. {
  13.   printf("dat2l lisespec textfile timecal ycal\n");
  14.   printf("  converts spectra from a textfile to lise format\n");
  15.   printf("  file format:\n");
  16.   printf("     ymax ymin zero_line\n");
  17. }
  18.  
  19. iabs(x)
  20. int x;
  21. {
  22.    if(x >= 0) return(x);
  23.    return(-1 * x);
  24. }
  25.  
  26. main(argc,argv)
  27. int argc;
  28. char *argv[];
  29. {
  30. int n,m,i,max;
  31. int y1,y2,y0;
  32. char z[80],comment[80];
  33. FILE *fp;
  34. float ycal;
  35.  
  36.    if(argc != 5) {
  37.       help();
  38.       exit(0);
  39.    }
  40.  
  41.    spc= (float *)calloc(_MAXSPCLEN+2,sizeof(float));
  42.    err= (float *)calloc(_MAXSPCLEN+2,sizeof(float));
  43.    tim= (float *)calloc(_MAXSPCLEN+2,sizeof(float));
  44.    if(tim==NULL) {
  45.       printf("sorry, not enough memory\n");
  46.       exit(-1);
  47.    }
  48.  
  49.    strcpy(z,argv[2]);
  50.    fp = fopen(z,"r");
  51.    if(fp == NULL) {
  52.       printf("Could not open file >%s<\n",z);
  53.       exit(0);
  54.    }
  55.  
  56.    _tica = atosf(argv[3]);
  57.    ycal = atosf(argv[4]);
  58.    max = 0;
  59.    while(!feof(fp)) {
  60.       fscanf(fp,"%d %d %d\n",&y1,&y2,&y0);
  61.       i = iabs(y1 - y2);
  62.       err[max] = 0.5 * ycal * (float) i;
  63.       i = (y1 + y2) >> 1;
  64.       i = i - y0;
  65.       spc[max] = ycal * (float) i;
  66.       tim[max] = _tica * (float) max;
  67.       max = max + 1;
  68.    }
  69.    
  70.    strcpy(z,argv[1]);
  71.    writespec(z,spc,err,max,2,"lazarus");
  72.    strcat(z,".tim");
  73.    writespec(z,tim,err,max,2,"lazarus");
  74.    free(err); free(spc); free(tim);
  75.    exit(0);
  76. }
  77.  
  78.